<template>
    <div class="column-detail-page w-75 mx-auto">
        <div class=" row mb-4 border-bottom pb-4 align-items-center"></div>
        <div class="col-3 text center">
            <img :src="column.avatar && column.avatar.fitUrl" :alt="column.title" class="rounded-circle w-100">
        </div>
        <div class="col-9">
            <h4>{{column?.title}}</h4>
            <p class="text-muted">{{column?.description}}</p>
        </div>
        <PostList :list="list"></PostList>
        <!-- <pre>{{route}}</pre> -->
    </div>
</template>

<script lang="ts" setup>
import { useRoute } from 'vue-router';
import { useStore } from 'vuex';
import { ColumnProps, GlobalDataProps } from '@/types';
import PostList from '@/components/PostList.vue';
import { computed, onMounted } from 'vue';
import { generateFitUrl } from '@/utils/FileUtils';

const route = useRoute();
const store = useStore<GlobalDataProps>();
const currentId = route.params.id;
onMounted(() => {
    store.dispatch('fetchColumn', currentId);
    store.dispatch('fetchPosts', currentId);
})
const column = computed(() => {
    const selectColumn = store.getters.getColumnById(currentId) as ColumnProps;
    if (selectColumn) {
        generateFitUrl(selectColumn, 100, 100);
    }
    return selectColumn;
});
const list = computed(() => store.getters.getPostsByCid(currentId));
// console.log(list.value);
</script>